# -*-coding:utf-8-*-
import re, os, sys


def readFasta(file):
    if os.path.exists(file) == False:
        print('Error:"' + file + '"dose not exist.')
        sys.exit(1)

    with open(file) as f:
        records = f.read()

    if re.search('>', records) == None:
        print('The input file seems not in fasta format.')
        sys.exit(1)

    records = records.split('>')[1:]
    myFasta = []
    for fasta in records:
        array = fasta.split('\n')
        # [^ABC]匹配除了 [...] 中字符的所有字符
        name, sequence = array[0].split()[0], re.sub('[^ARNDCQEGHILKMFPSTWYV-]', '-', ''.join(array[1:]).upper())
        myFasta.append([name, sequence])
    return myFasta


if __name__ == '__main__':
    readFasta('P42212.fasta')
